package com.zxp.mylib.test.type.aaaa.bb

import com.custom.base.entity.OkHttpBodyEntity
import com.custom.base.entity.PageModel
import com.custom.base.http.OkHttpFromBoy
import com.custom.base.http.SDOkHttpResoutCallBack
import com.custom.base.manager.SDActivityManager
import com.custom.base.mvp.BasePresenterImpl

/**
 * 作者：
 * 时间：2022-06-10
 * 描述：
 */

class BbPresenter : BasePresenterImpl<BbContract.View>(), BbContract.Presenter{
    private var list = arrayListOf<BbModel.Data>()
    private var adapter:BbAdapter? = null
    private var page = PageModel()

    override fun init() {
        mView?.apply {
            for(i in 1..10){
                list.add(BbModel.Data(""))
            }
            adapter = BbAdapter(list, SDActivityManager.instance.lastActivity)
            page.initPullToRefreshListView(listView,adapter)
            page.request(object : OkHttpFromBoy {
                override fun addBody(requestBody: OkHttpBodyEntity) {
                    requestBody.setPost("")
                    requestBody.addPage(page)
                }
            },object : SDOkHttpResoutCallBack<BbModel>() {
                override fun onSuccess(entity: BbModel) {
                    page.updateAdapterByList(list,entity.list,adapter)
                }

                override fun onFinish() {
                    page.onRefreshComplete()
                }
            })
        }
    }
}